<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script src="js/ajax.js"></script>
<script>
	function gender(){
		//获取ajax对象
		var xhr=getXhr();
		//发送请求
		
		xhr.open('post','gender.do',true);
		console.log(xhr.readyState);
		xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
		xhr.send('');

		
		xhr.onreadystatechange=function (){   //该事件类似一个线程,与gender方法同步执行
			console.log(xhr.readyState);
			if(xhr.readyState==4&&xhr.status==200){
				var t=xhr.responseText;
				$('ran').value=t;
			}
		}
					
			
			
	}	
	

</script>



<body>

	<form action="" method="post">
		
		<input type="text" id="ran"/>
		<input type="button" value="点击生成随机数" 
			onclick="gender();"/>
				
	</form>



</body>
</html>